<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/bootstrap3/bootstrap.autocomplete.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/res/third/ueditor/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript">
</script>

<style type="text/css">
</style>

</head>

<body>
	<div id="editcontract" style="padding-top: 20px">
		<form id="editcontractform" action="o_edit.do" method="post" class="form-horizontal" role="form">

			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">合同名称</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" placeholder="请输入合同名称" min="1" required="required" name="name" value="${contract.name!}">

				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">公司名称</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" required="required" name="companyname" id="companyname" autocomplete="off" value="${contract.company.companyName!}" real-value="${contract.company.id!}"> 
					<input type="hidden" name="companyId" id="companyId" value="${contract.company.id!}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">合同类型</label>
				<div class="col-sm-10">
					<div class="form-ctrl form-radio">
						[#list dictionarys as dictionary]
						<span>
							<input type="radio" name="type" value="${dictionary.code!}" [#if contract.type??][#if (contract.type?substring(0))==dictionary.code] checked="checked" [/#if][/#if]/>${dictionary.name!}
						</span>
						[/#list]
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">是否默认模板</label>
				<div class="col-sm-10">
					<div class="form-ctrl form-radio">
						<span>
							<input type="radio" name="ifDefault" value="1" [#if contract.ifDefault??][#if contract.ifDefault==1]checked= "checked"[/#if][/#if]/>是
						</span>
						<span>
							<input type="radio" name="ifDefault" value="0" [#if contract.ifDefault??][#if contract.ifDefault==0]checked= "checked"[/#if][/#if]/>否
						</span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">合同内容</label>
				<div class="col-sm-10">
					<div class="form-ctrl form-radio">
						<script id="container" name="content" type="text/plain">${contract.content!}</script>
					</div>
				</div>
			</div>
			<input type="hidden" name="id" value="${contract.id!}"> <input type="hidden" name="state" value="${contract.state!}">

			<div class="form-group" style="margin-top: 10px;">
				<div class="col-sm-offset-2 col-sm-10">
					<input id="editsubmit" type="button" class="btn btn-default" value="提交" />
				</div>
			</div>
		</form>
	</div>
</body>
</html>
<script type="text/javascript">
	var editor;
	$(function() {

		var option = {
			theme : "default",
			lang : "zh-cn",
			initialFrameWidth : 800,
			initialFrameHeight : 350,
			autoHeightEnabled : false,
			pasteplain : true,//默认纯文本格式粘贴,
			elementPathEnabled : false,
			focus : false,//初始化时不让编辑器获取焦点
			toolbars : [ [ 'fullscreen', 'source', 'undo', 'redo', 'bold',
					'indent', 'italic', 'underline', 'strikethrough',
					'justifyleft', 'justifyright', 'justifycenter',
					'justifyjustify', 'rowspacingtop', 'rowspacingbottom',
					'lineheight', 'removeformat', '|', 'fontfamily',
					'fontsize', 'forecolor', 'backcolor', 'insertorderedlist',
					'insertunorderedlist', 'insertimage', 'emotion',
					'inserttable', 'mergeright', 'mergedown', 'deleterow',
					'deletecol', 'splittorows', 'splittocols', 'splittocells',
					'deletecaption', 'mergecells', 'deletetable' ] ]
		};
		editor = UE.getEditor('container', option);
		$("span[class='combo']").css({
			"height" : "30px",
			"border-radius" : "4px",
			"width" : "180px"
		});
		$("span[class='combo-arrow']").css({
			"height" : "30px"
		});
		$("input[class^='combo-text']").css({
			"height" : "30px",
			"width" : "160px"
		});

		$('#companyname').autocomplete({
			source : function(query, process) {
				var matchCount = 6; //this.options.items;返回结果集最大数量
				$.post("/company/autocustomer.do", {
					"query" : query,
					"matchCount" : matchCount
				}, function(respData) {
					var json = JSON.parse(respData);
					return process(json.obj);
				});
			},
			formatItem : function(items) {
				return items["company"];
			},
			setValue : function(items) {
				return {
					'data-value' : items["company"],
					'real-value' : items["id"]
				};
			}
		});
	});

	$('#editsubmit').click(function() {
		if ($("#companyname").val() == "") {
			$("#companyname").attr('real-value', '');
		}

		var name = $("input[name='name']").val();
		if (!name) {
			alert('合同名称必须填写!');
			return;
		}
		var companyId = $("input[name='companyname']").attr('real-value');
		if (!companyId) {
			alert('必须选择一个正确的公司!');
			return;
		}
		var type = $("input[name='type']:checked").val();
		if (!type) {
			alert('请选择合同类型!');
			return;
		}
		var ifDefault = $("input[name='ifDefault']:checked").val();
		if (!ifDefault) {
			alert('请选择是否默认模板!');
			return;
		}

		var companyId = $("#companyname").attr('real-value')
		$("#companyId").val(companyId);
		var form = $("#editcontractform").serializeArray();
		$.ajax({
			type : "post",
			dataType : "text",
			contentType : "application/json; charset=utf-8",
			url : "/contract/o_edit.do",
			data : JSON.stringify({
				name : form[0].value,
				company :{ 
					companyName:form[1].value,
					id:form[2].value
				},
				type : form[3].value,
				ifDefault : form[4].value,
				id : form[5].value,
				state : form[6].value,
				content : form[7].value

			}),
			success : function(data) {//成功的时候调用
				top.closeTempTab(true);
			}
		});

		//top.closeTempTab(true);
	});
</script>
